package 剑指offer;

import java.util.Arrays;

public class p268丢失的数字 {
    public int missingNumber(int[] nums) {
        int len=nums.length;
        boolean[] findMiss=new boolean[len+1];

        for (int i = 0; i <len; i++) {
            findMiss[nums[i]]=true;
        }

        for (int i = 0; i <findMiss.length; i++) {
            if (!findMiss[i]) {
                return i;
            }
        }
        return -1;
    }


    public int missingNumber1(int[] nums) {
        //排序
        Arrays.sort(nums);
        for (int i = 0; i <nums.length; i++) {
            if (nums[i] != i) {
                return i;
            }
        }

        //有 0-nums.length，没有最后一个数，所以返回最后一个数
        return nums.length;

    }
}
